<template>
  <el-container class="main_con">
    <ufrom @submit="saveData" ref="ufrom">
      <el-form size="medium" label-width="100px">
        <div class="setting_body_item">
          <div class="header">维权设置</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label="售后维权">
                <el-radio-group v-model="obj.configuration.is_rights_apply">
                  <el-radio :label="0">订单收货后不允许售后</el-radio>
                  <el-radio :label="1">允许售后</el-radio>
                </el-radio-group>
                <div v-if="obj.configuration.is_rights_apply == 1" style="color:#909399;font-size:12px;">
                  订单完结之前都可以售后,
                  <el-button type="text"><el-link href="#/order/setting/deal" :underline="false">设置订单完成时间</el-link></el-button>
                </div>
              </el-form-item>
              <el-form-item label="退款说明">
                <el-input type="textarea" rows="2" v-model="obj.configuration.refund_explain" style="width:360px;"></el-input>
                <div style="color:#909399;font-size:12px;">用户在申请退款页面的说明</div>
              </el-form-item>

              <el-form-item label="单品退换货">
                <el-radio-group v-model="obj.configuration.refund_single">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
                <div style="color:#909399;font-size:12px;">开启后，订单支持单件商品退换，订单优惠金额按比例分摊至每件商品</div>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
    </ufrom>
  </el-container>
</template>

<script>
import {addSiteConfig, editSiteConfig, getSiteConfig} from '@/api/mall/setting';
export default {
  data() {
    return {
      isLoading: false,
      checkList: [],
      obj: {
        type: 'rightsSetting',
        status: 1,
        configuration: {
          is_rights_apply: 0,
          rights_apply_time: 0,
          refund_explain: '',
          refund_single: 0
        }
      }
    };
  },
  components: {},
  mounted() {
    this.getConfig('rightsSetting');
  },
  methods: {
    //获取站点配置数据
    getConfig(type) {
      getSiteConfig(type)
        .then(res => {
          if (res.msg) {
            this.obj = res.msg;
          }
        })
        .catch(e => {});
    },
    //保存数据
    saveData() {
      this.isLoading = true;
      if (this.obj.update_time) {
        //更新
        editSiteConfig(this.obj)
          .then(res => {
            this.$refs.ufrom.init();
            this.getConfig('rightsSetting');
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      } else {
        //新增
        addSiteConfig(this.obj)
          .then(res => {
            this.$refs.ufrom.init();
            this.getConfig('rightsSetting');
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      }
    }
  }
};
</script>
